package com.qgs.rabbitmqapi.dlx;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 蔡翔
 * @Date: 2019/7/19 13:27
 * @Version 1.0
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.0.229");
        connectionFactory.setVirtualHost("/");
        connectionFactory.setPort(5672);

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        String exchange = "test_dlx_exchange";
        String routingKey = "dlx.save";

        String msg = "hello rabbitmq DLX message";

        AMQP.BasicProperties basicProperties = new AMQP.BasicProperties().builder()
                .deliveryMode(2)
                .contentEncoding("UTF-8")
                .expiration("10000")
                .build();
        //要先启动Consumer端 让队列和交换机先声明，然后关掉，让生产者生产出5条10s过期的消息，这5条消息10s以后就自动进入死信队列了。
        for(int i=0;i<5;i++){
            channel.basicPublish(exchange,routingKey,true,basicProperties,msg.getBytes());
        }


    }
}
